/*
 * LengthCellRenderer.java
 *
 * Created on April 2, 2006, 11:42 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.bff.mpd.musicjukebox.ui.components;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.SwingConstants;

/**
 *
 * @author Bill
 */

public class LengthCellRenderer extends SongCellRenderer {
        
    private static final float SECONDS_PER_MINUTE = 60;
    private static final int NUM10 = 10;
   
    public LengthCellRenderer() {
        super();
        setHorizontalAlignment(SwingConstants.CENTER);
    }
        
    @Override
    public Component getTableCellRendererComponent(
            JTable table,
            Object value,
            boolean isSelected,
            boolean hasFocus,
            int row,
            int column) {
        super.setFont(table.getFont());

        if(value instanceof Integer) {
            int seconds = (Integer)value;
            setText("0:00");
            
            if (seconds > 0) {
                int secs = (int) (seconds % SECONDS_PER_MINUTE);
                setText(((int) (seconds / SECONDS_PER_MINUTE)) + ":"
                        + (secs < NUM10 ? "0" + secs : Integer.toString(secs)));
            }
        }

        setColors(table, row, isSelected);
        return this;
    }
}
